// ================================================================================
// 		File: partyJoinContact.cs
// 		Desc: 
//  
// 		Called by:   
//               
// 		Auth: chenwenzhi（--）
// 		Date: 2015-12-28 23:59
// ================================================================================
// 		Change History
// ================================================================================
// 		Date:		Author:				Description:
// 		--------	--------			-------------------
//    
// ================================================================================
//
// ================================================================================
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using ZHDJ.Core;

namespace ZHDJ.Data.Models.JoinParty
{
    /// <summary>
    /// 
    /// </summary>   
    public class partyJoinContact : EntityBase
    {
        #region 属性

        /// <summary>
        /// AppllicationID
        /// </summary>
        [StringLength(128)]
        public string AppllicationID { get; set; }

        /// <summary>
        /// ContactName
        /// </summary>
        [StringLength(512)]
        public string ContactName { get; set; }

        /// <summary>
        /// ContactID
        /// </summary>
        [StringLength(128)]
        public string ContactID { get; set; }

        /// <summary>
        /// InParty
        /// </summary>
        [StringLength(128)]
        public string InParty { get; set; }

        /// <summary>
        /// Administration
        /// </summary>
        [StringLength(512)]
        public string Administration { get; set; }

        /// <summary>
        /// PartyStanding
        /// </summary>
        [StringLength(512)]
        public string PartyStanding { get; set; }

        /// <summary>
        /// ContactTime
        /// </summary>
        public DateTime? ContactTime { get; set; }

        /// <summary>
        /// 联系人类型
        /// 0：入党培养人
        /// 1：入党介绍人
        /// </summary>
        public int ContactType { get; set; }

        #endregion

        /// <summary>
        /// 获取GetDataGrid数据源
        /// </summary>
        /// <returns></returns>
        public static DataSet GetGridData(string AppllicationID,int contacttype)
        {
            StringBuilder sbSql = new StringBuilder();
            sbSql.AppendFormat(@"select jc.*,ou.LoginID,ou.UserName,sp.DDicMemberName as GenderName,ou.Birthday
                                  ,ou.Educational,ou.NativePlace,ou.JoinPartyDate 
                               from tblpartyJoinContact jc 
                                left join tblpartyorgmember ou on jc.ContactID=ou.LoginID 
                                left join tbldatadictionary sp on ou.Gender=sp.DDicMember and sp.DDicType='{0}'
                               where jc.AppllicationID = '{1}' and jc.contacttype={2}", SysDataDictionary.GenderKey, AppllicationID, contacttype);
            sbSql.Append(" order by jc.ContactTime asc");
            return MySqlHelper.ExecuteDataSet(sbSql.ToString());

        }

        /// <summary>
        /// 获取联系人电话
        /// </summary>
        /// <param name="AppllicationID"></param>
        /// <returns></returns>
        public static DataSet GetContactMsg(string AppllicationID, int contacttype)
        {
            StringBuilder sbsql = new StringBuilder();
            sbsql.AppendFormat(@" select pjc.*,om.MobileNo from tblpartyJoinContact pjc
                                left join tblpartyorgmember om on pjc.ContactID=om.LoginID where pjc.AppllicationID='{0}' and pjc.contacttype={1}", AppllicationID, contacttype);
            DataSet ds = MySqlHelper.ExecuteDataSet(sbsql.ToString());
            return ds;
        }

        /// <summary>
        /// 删除指定联系人
        /// </summary>
        /// <param name="AppllicationID">申请ID</param>
        public static bool DeleteContacts(string AppllicationID, int contacttype)
        {

            string sql = string.Format("delete from tblpartyJoinContact where AppllicationID='{0}' and contacttype={1}", AppllicationID,contacttype);
            return MySqlHelper.ExecuteNonQuery(sql) > 0;

        }

        /// <summary>
        /// 获取党员用户信息
        /// </summary>
        /// <param name="UserIDs">主键ID列</param>
        /// <returns></returns>
        public static DataSet GetOrgMember(string UserIDs)
        {

            StringBuilder sbSql = new StringBuilder();
            sbSql.AppendFormat(@"select po.LoginID,po.BranchID,po.UserName,po.Post,po.JoinPartyDate,sp.DDicMemberName as GenderName,po.Birthday,po.Educational,po.NativePlace from tblpartyorgmember po 
                               left join tbldatadictionary sp on po.Gender=sp.DDicMember and sp.DDicType='{0}' where 1=1", SysDataDictionary.GenderKey);
            if (!string.IsNullOrEmpty(UserIDs))
            {
                string IDs = string.Empty;
                int i = 0;
                foreach (string UserID in UserIDs.Split(','))
                {
                    IDs += "'" + UserID + "',";
                }
                sbSql.AppendFormat(" and po.LoginID in ({0})", IDs.Trim(','));
            }
            return MySqlHelper.ExecuteDataSet(sbSql.ToString());
        }
    }
}

